package com.talos.framework.common.pojo;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.talos.framework.common.annotation.FieldSearch;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

@Data
public class QueryDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    @JsonAlias(value = "current")
    @Schema(description = "当前页码")
    private Long pageNum;

    @JsonAlias(value = "size")
    @Schema(description = "每页条数")
    private Long pageSize;

    @Schema(description = "查询内容")
    private String keywords;

    @Schema(description="选项卡编码")
    private String tabCode;

    @Schema(description="子选项卡编码")
    private String subTabCode;

    @FieldSearch(value = "`id`")
    @Schema(description = "主键")
    private Long id;

    @FieldSearch(value = "`id`", in = true)
    @Schema(description = "主键列表")
    private List<Long> ids;

    @FieldSearch(value = "`create_time`", between = "getCreateEndedTime")
    @Schema(description = "创建时间开始")
    private LocalDateTime createBeganTime;

    @Schema(description = "创建时间结束")
    private LocalDateTime createEndedTime;

    @FieldSearch(value = "`creator_id`")
    @Schema(description = "创建人主键")
    private Long creatorId;

    @FieldSearch(value = "`creator_code`")
    @Schema(description = "创建人编码")
    private String creatorCode;

    @FieldSearch(value = "`creator_name`", like = true)
    @Schema(description = "创建人名称")
    private String creatorName;

    @JsonIgnore
    @Schema(hidden = true)
    public Long getPageNumOrDefault() {
        if (this.pageNum == null) {
            return 1L;
        }

        return this.pageNum;
    }

    @JsonIgnore
    @Schema(hidden = true)
    public Long getPageSizeOrDefault() {
        if (this.pageSize == null) {
            return 30L;
        }

        if (this.pageSize > 300) {
            return 300L;
        }

        return this.pageSize;
    }

}
